<?php
//page permettant d'�diter une commande dans le cadre des orderpreparation
$Order = $this->GetOrder();
?>

<form name="form_preparation" id="form_preparation" method="POST" action="<?php echo $this->getUrl('OrderPreparation/OrderPreparation/SaveOrder') ?>">
    <input name="form_key" type="hidden" value="<?php echo $this->getFormKey() ?>" />
    <input type="hidden" id="order_id"  name="order_id" value="<?php echo $Order->getId(); ?>">

    <div class="entry-edit">
        <div class="entry-edit-head">
            <h4><?php echo Mage::helper('AdvancedStock')->__('Preparation information') ?></h4>
        </div>
        <fieldset>
            <?php
            $OrderToPrepare = $this->getOrderToPrepare();
            if ($OrderToPrepare == null) {
                echo "<p><font color='red'>" . $this->__('This order doesnt belong to selected orders') . "</font></p>";
            } else {
                //cree le menu deroulant pour les shipments
                $ComboShipment = $this->getShipmentsAsCombo('shipment_id', $this->OrderToPrepare->getshipment_id());

                //cree le menu deroulant pour les shipments
                $ComboInvoice = $this->getInvoicesAsCombo('invoice_id', $this->OrderToPrepare->getinvoice_id());

                //recupere le no de tracking
                $tracking = "";
                foreach ($Order->getTracksCollection() as $track) {
                    if (is_object($track->getNumberDetail()))
                        $tracking = $track->getNumberDetail()->gettracking();
                    else {
                        if (is_array($track->getNumberDetail()))
                            $tracking = ' ';
                    }
                }
            ?>
                <table border="0">
                    <tr>
                        <td><?php echo $this->__('Shipment'); ?> : </td>
                        <td><?php echo $ComboShipment; ?></td>
                    </tr>
                    <tr>
                        <td><?php echo $this->__('Invoice'); ?> : </td>
                        <td><?php echo $ComboInvoice; ?></td>
                    </tr>
                    <tr>
                        <td><?php echo $this->__('Tracking'); ?> : </td>
                        <td>
<?php if ($tracking == '') { ?>
                                <input type="text" id="tracking_num" name="tracking_num" style="width: 350px;">
<?php } else { ?>
<?php echo $tracking; ?>
<?php } ?>
                        </td>
                    </tr>
                </table>
                        <?php
                    }
                        ?>

            <p>
<?php if ($Order->IsCompletelyShipped()): ?>
            <?php echo $this->__('Order completely shipped'); ?>
            <?php else: ?>
            <?php echo $this->__('Order not completely shipped'); ?>
<?php endif; ?>
                            </p>

                            <p>
                <?php if (mage::helper('AdvancedStock/Sales_ValidOrders')->orderIsValid($Order)): ?>
                <?php echo $this->__('Order is valid'); ?>
                <?php else: ?>
<?php echo $this->__('Order is not valid'); ?>				
<?php endif; ?>
                                    &nbsp;(<a href="<?php echo $this->getUrl('AdvancedStock/Order/UpdateIsValid', array('order_id' => $Order->getId())); ?>"><?php echo $this->__('Update'); ?></a>)
                                </p>

                                <p>
                <?php
									$warehouse = mage::helper('AdvancedStock/Sales_Order')->getPreparationWarehouse($Order);
                                    if ($warehouse != null)
                                        echo $this->__('Order is prepared from warehouse %s', $warehouse->getstock_name());
                ?>
                                </p>

                                <p>
                <?php
                                    if ($Order->productReservationAllowed())
                                        echo $this->__('Product reservation enabled');
                                    else
                                        echo $this->__('Product reservation disabled');
                ?>
                                </p>

                            </fieldset>
                        </div>

        <div class="entry-edit">
            <div class="entry-edit-head">
                <h4><?php echo Mage::helper('AdvancedStock')->__('Change shipping method') ?></h4>
            </div>
            <fieldset>
               <table cellspacing="0" class="form-list">
                <tr>
                    <td class="label"><label><?php echo $this->__('Change to'); ?></label></td>
                    <td><?php echo $this->getShippingMethodsAsCombo('shipping_method'); ?></td>
                </tr>
               </table>
            </fieldset>
        </div>


                        <div class="a-right" style="margin-bottom: 10px;">
                            <button onclick="document.location.href='<?php echo $this->getPrintUrl(); ?>'" class="scalable" type="button"><span><?php echo $this->__('Print') ?></span></button>
                            <button onclick="document.location.href='<?php echo $this->getReleaseAllProductsUrl(); ?>'" class="scalable" type="button"><span><?php echo $this->__('Release all products') ?></span></button>
                                <?php if ($Order->productReservationAllowed()): ?>
                                                                <button onclick="document.location.href='<?php echo $this->getReserveAllProductsUrl(); ?>'" class="scalable" type="button"><span><?php echo $this->__('Reserve all products') ?></span></button>
                                <?php endif; ?>
                                <button onclick="document.getElementById('form_preparation').submit()" class="scalable save" type="button"><span><?php echo $this->__('Save') ?></span></button>
                            </div>

                            <div class="grid">
                                <table cellspacing="0" class="data" width="100%">
                                    <thead>
                                        <tr class="headings">
                                            <th class="a-center"><?php echo $this->__('Name') ?></th>
                                                    <th class="a-center"><?php echo $this->__('Comments') ?></th>
                                                    <th class="a-center"><?php echo $this->__('Serials') ?></th>
                                                    <th class="a-center"><?php echo $this->__('Ordered Qty') ?></th>
                                                    <th class="a-center"><?php echo $this->__('Shipped Qty') ?></th>
                                                    <th class="a-center"><?php echo $this->__('Remains to ship') ?></th>
                                                    <th class="a-center"><?php echo $this->__('Reserved Qty') ?></th>
                                                    <th class="a-center"><?php echo $this->__('Shelf<br>Location') ?></th>
                                                    <th class="a-center"><?php echo $this->__('Action') ?></th>
                                                </tr>
                                            </thead>
                                            <tbody>
<?php
                                        $collection = $this->getOrder()->getItemsCollection();
                                        foreach ($collection as $item):
?>
                                                    <tr>
                                                        <td><a href="<?php echo $this->getUrl('AdvancedStock/Products/Edit', array('product_id' => $item->getproduct_id())); ?>"><?php echo $item->getname() . mage::helper('AdvancedStock/Product_ConfigurableAttributes')->getDescription($item->getproduct_id()); ?></a></td>
                                                        <td class="a-center"><textarea cols="40" rows="4" id="comments_<?php echo $item->getId(); ?>" name="comments_<?php echo $item->getId(); ?>"><?php echo $item->getcomments(); ?></textarea></td>
                                                <td class="a-center"><textarea cols="40" rows="4" id="serials_<?php echo $item->getId(); ?>" name="serials_<?php echo $item->getId(); ?>"><?php echo $item->getserials(); ?></textarea></td>
                                                <td class="a-center"><?php echo (int) $item->getqty_ordered(); ?></td>
                                                <td class="a-center"><?php echo (int) $item->getRealShippedQty(); ?></td>
                                                <td class="a-center"><?php echo (int) $item->getRemainToShipQty(); ?></td>
                                                <td class="a-center"><?php echo (int) $item->getreserved_qty(); ?></td>
                                                <td class="a-center"><?php echo $warehouse->getProductLocation($item->getproduct_id()); ?></td>
                                                <td class="a-center"><?php echo $this->getReservedColumnHtml($item); ?></td>
                                            </tr>
<?php endforeach; ?>
            </tbody>
        </table>
    </div>

</form>